/* GUI CONVERTED from reoptr1a.p (converter v1.76) Tue Apr 23 11:43:55 2002 */
/* reoptr1a.p - LABOR OPERATION TRANSACTION SUBROUTINE                  */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.32 $                                                    */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 6.0      LAST MODIFIED: 07/25/90   BY: emb *D033*          */
/* REVISION: 6.0      LAST MODIFIED: 09/24/90   BY: SMM *D072*          */
/* REVISION: 6.0      LAST MODIFIED: 10/10/90   BY: SMM *D085*          */
/* REVISION: 6.0      LAST MODIFIED: 12/19/90   BY: emb *D265*          */
/* REVISION: 6.0      LAST MODIFIED: 06/07/91   BY: emb *D680*          */
/* REVISION: 6.0      LAST MODIFIED: 09/17/91   BY: WUG *D858*          */
/* REVISION: 6.0      LAST MODIFIED: 10/07/91   BY: alb *D887*          */
/* REVISION: 7.0      LAST MODIFIED: 10/08/91   BY: pma *F003*          */
/* REVISION: 7.0      LAST MODIFIED: 03/09/92   BY: smm *F230*          */
/* REVISION: 7.0      LAST MODIFIED: 03/19/92   BY: RAM *F298*          */
/* REVISION: 7.0      LAST MODIFIED: 03/29/92   BY: emb *F331*          */
/* REVISION: 7.0      LAST MODIFIED: 07/07/92   BY: emb *F729*          */
/* Revision: 7.3          Last edit: 09/27/93   By: jcd *G247*          */
/* REVISION: 7.3      LAST MODIFIED: 12/29/92   BY: pma *G382*          */
/* REVISION: 7.3      LAST MODIFIED: 11/04/92   BY: emb *G689*          */
/* REVISION: 7.3      LAST MODIFIED: 02/26/93   BY: emb *G760*          */
/* REVISION: 7.3      LAST MODIFIED: 10/19/93   BY: pxd *GG41*          */
/* REVISION: 7.4      LAST MODIFIED: 01/12/94   BY: qzl *H276*          */
/* REVISION: 7.4      LAST MODIFIED: 07/29/94   BY: pxd *FP68*          */
/* REVISION: 7.4      LAST MODIFIED: 09/15/94   by: slm *GM63*          */
/* REVISION: 7.4      LAST MODIFIED: 10/10/94   by: pxd *FR91*          */
/* REVISION: 7.4      LAST MODIFIED: 11/06/94   by: rwl *GO29*          */
/* REVISION: 7.4      LAST MODIFIED: 11/08/94   by: srk *GO05*          */
/* REVISION: 7.4      LAST MODIFIED: 12/06/94   by: emb *FU13*          */
/* REVISION: 7.5      LAST MODIFIED: 12/12/94   by: taf *J038*          */
/* REVISION: 7.2      LAST MODIFIED: 12/15/94   BY: WUG *F09S*          */
/* REVISION: 7.3      LAST MODIFIED: 01/04/95   BY: qzl *G0BF*          */
/* REVISION: 7.4      LAST MODIFIED: 01/05/95   BY: cpp *FT95*          */
/* REVISION: 7.5      LAST MODIFIED: 01/05/95   BY: pma *J040*          */
/* REVISION: 7.5      LAST MODIFIED: 01/06/95   BY: ktn *J041*          */
/* REVISION: 7.3      LAST MODIFIED: 11/01/95   BY: ais *G0V9*          */
/* REVISION: 7.3      LAST MODIFIED: 11/01/95   BY: qzl *G0WC*          */
/* REVISION: 8.5      LAST MODIFIED: 04/26/96   BY: jym *G1TH*          */
/* REVISION: 8.5    LAST MODIFIED: 10/21/96 BY: *G2H7* Julie Milligan   */
/* REVISION: 8.5    LAST MODIFIED: 12/26/96 BY: *H0Q8* Julie Milligan   */
/* REVISION: 8.5    LAST MODIFIED: 09/22/97 BY: *H1FD* Felcy D'Souza    */
/* REVISION: 8.5    LAST MODIFIED: 11/06/97 BY: *J25H* Sandesh Mahagaokar   */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane        */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan       */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan       */
/* REVISION: 8.6E     LAST MODIFIED: 10/08/98   BY: *J31F* Mugdha Tambe     */
/* REVISION: 9.0      LAST MODIFIED: 12/01/98   BY: *J35X* Thomas Fernandes */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan       */
/* REVISION: 9.0      LAST MODIFIED: 03/30/99   BY: *J39K* Sanjeev Assudani */
/* REVISION: 9.1      LAST MODIFIED: 09/04/99   BY: *J3KM* G.Latha          */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates       */
/* REVISION: 9.1      LAST MODIFIED: 11/03/99   BY: *N050* Bill Gates       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 06/23/00   BY: *L105* Santhosh Nair    */
/* REVISION: 9.1      LAST MODIFIED: 07/24/00   BY: *N0GS* B. Gates         */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb              */
/* Old ECO marker removed, but no ECO header exists *F0PN*                  */
/* Revision: 1.30     BY: Rajesh Thomas    DATE: 06/19/01 ECO: *M18V*     */
/* Revision: 1.31  BY: Irine D'Mello    DATE: 09/10/01 ECO: *M164*  */
/* $Revision: 1.32 $    BY: Samir Bavkar   DATE: 04/05/02 ECO: *P000*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE reoptr1a_p_1 "Modify Backflush"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1a_p_2 "Down Time"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1a_p_3 "Input Total"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1a_p_4 "Elapsed or Stop Time"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1a_p_5 "Control Total"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1a_p_6 "Conv"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1a_p_7 "BOM"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1a_p_8 "Completed"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1a_p_9 "Chg Attributes"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1a_p_10 "Start Time"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1a_p_11 "Status"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1a_p_12 "Reason"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr1a_p_13 "Routing"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define new shared variable part like op_part no-undo.
define new shared variable op like ps_op no-undo.

define shared variable wr_recno as recid.
define shared variable wc_recno as recid.
define shared variable op_recno as recid.
define shared variable comp like ps_comp.
define shared variable eff_date as date.
define shared variable wo_recid as recid.
define shared variable wo_recno as recid.
define shared variable ophist_recid as recid.
define shared variable pay_rate like emp_pay_rate.
define shared variable global_rsntyp as character.
define shared variable undo-input-top like mfc_logical no-undo.
define shared variable move_to_wkctr like wc_wkctr no-undo.
define shared variable move_to_mch like wc_mch no-undo.
define shared variable conv_factor as decimal no-undo.
define shared variable h_wiplottrace_procs as handle no-undo.
define shared variable h_wiplottrace_funcs as handle no-undo.
define shared variable last_date like op_date.
define shared variable input_total as decimal format "->>9.9<<"
   label {&reoptr1a_p_3}.
define shared variable control_total like input_total label {&reoptr1a_p_5}.
define shared variable downtime like input_total extent 5
   label {&reoptr1a_p_2}.
define shared variable down_rsn like rsn_code extent 5 label {&reoptr1a_p_12}.
define shared variable site like rps_site no-undo.
define shared variable prline like rps_line no-undo.
define shared variable bom_code as character format "x(18)"
   label {&reoptr1a_p_7}.
define shared variable routing as character format "x(18)"
   label {&reoptr1a_p_13}.
define shared variable schedule_id like wo_lot.
define shared variable mod_issrc like mfc_logical
   label {&reoptr1a_p_1}.
define shared variable chg_attr like mfc_logical
   label {&reoptr1a_p_9} no-undo.
define shared variable entered_qty_comp as decimal no-undo.
define shared variable entered_qty_rjct as decimal no-undo.

define variable rejected like mfc_logical.
define variable yn like mfc_logical.
define variable ref like glt_ref.
define variable wr_recid as recid.
define variable wocomp like mfc_logical label {&reoptr1a_p_8} initial no.
define variable wrstatus as character format "X(8)" label {&reoptr1a_p_11}.
define variable start_setup as character label {&reoptr1a_p_10}
   format "99:99:XX".
define variable start_run like start_setup.
define variable stop_setup like start_setup label {&reoptr1a_p_4}.
define variable stop_run like stop_setup.
define variable date_change as integer.
define variable elapse as decimal format ">>>>>>>>.999".
define variable trnbr like op_trnbr format ">>>>>>>9".
define variable wrnbr like wr_nbr.
define variable i as integer.
define variable j as integer.
define variable qty like op_qty_comp.
define variable rsn_desc1 like rsn_desc.
define variable rsn_desc2 like rsn_desc.
define variable rsn_desc3 like rsn_desc.
define variable old_emp like op_emp.
define variable down_desc like rsn_desc extent 5.
define variable shift like op_shift.
define variable earn like op_earn.
define variable location as character.
define variable conv like um_conv label {&reoptr1a_p_6}.
define variable um like pt_um.
define variable tot_units like op_qty_comp.
define variable disp_units as character format "x(15)".
define variable undo-input like mfc_logical no-undo.
define variable forced_modissrc as log.
define variable temp_qty like pk_qty no-undo.
define variable trans-ok like mfc_logical.
define variable trqty like pk_qty no-undo.
define variable result_status as character no-undo.
define variable undo_stat like mfc_logical no-undo.
define variable consider_output_qty like mfc_logical no-undo.
define variable old_mod_issrc as logical no-undo.

/* DEFINE VARIABLES FOR BILL OF MATERIAL EXPLOSION */
{gpxpld01.i "shared"}

/*DEFINE VARIABLES FOR CHANGE ATTRIBUTES FEATURE*/
{gpatrdef.i "shared"}

define shared frame a.
define shared frame b.

define buffer ophist for op_hist.
define buffer ptmstr for pt_mstr.

{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/
{wlcon.i}

{reopf10a.i} /* Frame a definition */

{reopf10b.i} /* Frame b definition */

undo-input-top = yes.

find op_hist exclusive-lock where recid(op_hist) = op_recno.
find wr_route no-lock where recid(wr_route) = wr_recno.
find wo_mstr no-lock where recid(wo_mstr) = wo_recno.
find pt_mstr where pt_part = op_part no-lock no-error.

assign
   um = ""
   conv = 1
   global_rsntyp = "downtime".

loop1:
do on error undo, retry with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.


   set_ophist:
   do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


      display input_total with frame a.

      set op_wkctr op_mch
      editing:

         {mfnp.i wc_mstr op_wkctr wc_wkctr op_wkctr wc_wkctr wc_wkctr}
         if recno <> ?
         then do:

            display
               wc_wkctr @ op_wkctr
               wc_mch @ op_mch
               wc_desc.

            find dpt_mstr no-lock
               where dpt_dept = wc_dept no-error.

            if available dpt_mstr
            then do:
               op_dept = dpt_dept.
               display op_dept dpt_desc.
            end.
            else
               display " " @ dpt_desc.
         end.
      end.

      find wc_mstr
         where wc_wkctr = op_wkctr
           and wc_mch = op_mch
         no-lock no-error.

      if not available wc_mstr
      then do:
         {pxmsg.i &MSGNUM=519 &ERRORLEVEL=3}
         /* WORK CENTER DOES NOT EXIST */
         undo, retry.
      end.

      display wc_desc.
      find dpt_mstr no-lock
         where dpt_dept = wc_dept no-error.

      if available dpt_mstr
      then do:
         op_dept = dpt_dept.
         display op_dept dpt_desc.
      end.
      else display " " @ dpt_desc.

      find ro_det
         where ro_routing = (if wo_routing > "" then wo_routing else wo_part)
           and ro_op = op_wo_op
           and (ro_start = ? or ro_start <= last_date)
           and (ro_end = ? or ro_end >= last_date) no-lock no-error.

      if (available ro_det and
         (op_wkctr <> ro_wkctr or op_mch <> ro_mch))
         or not available ro_det
      then do:

         ophist_recid = recid(op_hist).
         {gprun.i ""reupopst.p""
            "(input ophist_recid)"
            }
/*GUI*/ if global-beam-me-up then undo, leave.


      end.

      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         set
            op_dept
            op_qty_comp
            um conv
            op_qty_rjct
            mod_issrc
            chg_attr
            op_act_run
            op_earn
            downtime[1] down_rsn[1]
            downtime[2] down_rsn[2]
            editing:

            if frame-field = "op_dept"
            then do:

               {mfnp.i dpt_mstr op_dept dpt_dept
                  op_dept op_dept dpt_dept}
               if recno <> ?
               then
                  display dpt_dept @ op_dept dpt_desc.
            end.

            else if frame-field = "op_earn"
            then do:
               {mfnp.i ea_mstr op_earn ea_earn op_earn ea_earn ea_earn}
               if recno <> ? then display ea_earn @ op_earn ea_desc.
            end.

            else do:
               readkey.
               apply lastkey.
            end.
         end.

         find dpt_mstr
            where dpt_dept = op_dept no-lock no-error.

         if not available dpt_mstr
         then do:
            next-prompt op_dept.
            {pxmsg.i &MSGNUM=532 &ERRORLEVEL=3}
            /* DEPARTMENT DOES NOT EXIST. */
            undo, retry.
         end.

         display dpt_desc.

         if um <> pt_um or conv <> 1
         then do:

            if not conv entered
            then do:

               {gprun.i ""gpumcnv.p""
                  "(input um, input pt_um, input op_part, output conv)"}
/*GUI*/ if global-beam-me-up then undo, leave.


               if conv = ?
               then do:
                  {pxmsg.i &MSGNUM=33 &ERRORLEVEL=2}
                  conv = 1.
               end.
               display conv with frame b.
            end.

            assign
               tot_units = (op_qty_comp + op_qty_rjct) * conv
               disp_units = string(tot_units,"->,>>>,>>9.9<<<<<<<<")
                          + " " + pt_um
               disp_units = string(disp_units).

            display disp_units with frame b.
         end.
         else display conv " " @ disp_units with frame b.

         if op_earn > ""
         then do:

            find ea_mstr
               where ea_earn = op_earn no-lock no-error.

            if not available ea_mstr
            then do:

               {pxmsg.i &MSGNUM=4025 &ERRORLEVEL=3}
               /* INVALID EARNINGS CODE */
               next-prompt op_earn.
               undo, retry.
            end.
            display ea_desc.
         end.
         else display " " @ ea_desc.

         do i = 1 to 2:
            if downtime[i] = 0 then
            assign
               down_rsn[i] = ""
               down_desc[i] = "".
            else do:
               find rsn_ref
                  where rsn_code = down_rsn[i]
                    and rsn_type = "downtime" no-lock no-error.

               if not available rsn_ref
                  then do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

                  {pxmsg.i &MSGNUM=534 &ERRORLEVEL=3}
                  /* REASON CODE DOES NOT EXIST */
                  set down_rsn[i]
                  editing:

                     /* FIND NEXT/PREVIOUS RECORD */
                     {mfnp01.i rsn_ref down_rsn[i] rsn_code
                        ""downtime"" rsn_type rsn_type}

                     if recno <> ? then
                        display
                           rsn_code @ down_rsn[i]
                           rsn_desc @ down_desc[i].
                  end.

                  find rsn_ref
                     where rsn_code = down_rsn[i]
                       and rsn_type = "downtime" no-lock no-error.

                  if not available rsn_ref then undo, retry.
               end.
/*GUI*/ if global-beam-me-up then undo, leave.


               down_desc[i] = rsn_desc.
            end.

            display down_rsn[i] down_desc[i].
         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      if op_act_run = 0 then do on error undo, retry with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.

         set start_run stop_run.

         {mfctime.i start_run stop_run}
         op_act_run = elapse.

         display op_act_run.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      assign
         elapse = op_act_run
         input_total = input_total + op_act_run + downtime[1] + downtime[2].

      display input_total with frame a.

      /* CHECK FOR MASTER SPECIFICATION */

      {mpwindow.i
         wr_part
         wr_op
         "if wo_routing = """" then wr_part else wo_routing"
         last_date
         }

      /*CHANGE ATTRIBUTES*/
      /*INITIALIZE ATTRIBUTE VARIABLES WITH CURRENT SETTINGS*/
      assign
         chg_assay = wo_assay
         chg_grade = wo_grade
         chg_expire = wo_expire
         chg_status = wo_rctstat
         assay_actv = yes
         grade_actv = yes
         expire_actv = yes
         status_actv  = yes.

      /* SET AND UPDATE INVENTORY DETAIL ATTRIBUTES */
      pause 0.
      if chg_attr
      then do:

         {gprun.i ""worcat02.p"" "(input recid(wo_mstr),
                                   input chg_attr,
                                   input eff_date,
                                   input-output chg_assay,
                                   input-output chg_grade,
                                   input-output chg_expire,
                                   input-output chg_status,
                                   input-output assay_actv,
                                   input-output grade_actv,
                                   input-output expire_actv,
                                   input-output status_actv)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.

      yn = yes.

      /*V8+*/
            {mfgmsg10.i 12 1 yn} /*IS ALL INFO CORRECT?*/   

      if yn <> yes then undo, retry.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /*set_ophist*/

   assign
      wr_recno = recid(wr_route)
      wc_recno = recid(wc_mstr)
      op_recno = recid(op_hist)
      comp = wr_part
      eff_date = op_date
      operation = wr_op
      entered_qty_comp = op_qty_comp
      entered_qty_rjct = op_qty_rjct
      conv_factor = conv
      op_qty_comp = op_qty_comp * conv
      op_qty_rjct = op_qty_rjct * conv .

   if wo_bom_code <> "" then comp = wo_bom_code.

   op_list = "".
   if schedule_id > ""
   then do:

      {mfdel.i pk_det "where pk_user = mfguser"}

      for each wo_mstr no-lock
         where wo_lot = schedule_id,
         each wr_route no-lock
            where wr_lot = schedule_id
              and wr_op <= operation
            by wr_lot descending by wr_op descending:
/*GUI*/ if global-beam-me-up then undo, leave.


         if wr_milestone = yes and wr_op < operation then leave.
         op_list = op_list + fill(",",if op_list = "" then 0 else 1)
                 + string(wr_op).

         if can-find (loc_mstr where loc_loc = wr_wkctr
            and loc_site = wo_site) then
            location = wr_wkctr.
         else
            location = "".

         {gprun.i ""reopex01.p""
            "(wr_lot,wr_op,wo_site,wo_qty_ord,location)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.

   end.

   else do:

      for each ro_det no-lock
         where ro_routing = (if routing > "" then routing else wr_part)
           and ro_op <= operation
           and (ro_start <= eff_date or ro_start = ?)
           and (ro_end >= eff_date or ro_end = ?)
         by ro_routing descending by ro_op descending:

         if ro_milestone = yes and ro_op < operation then leave.
         op_list = op_list + fill(",",if op_list = "" then 0 else 1)
                 + string(ro_op).
      end.

      /* EXPLODE ASSEMBLY FOR THIS OPERATION TO ISSUE COMPONENTS */

      {gpxpldps.i &date=eff_date
         &site=site
         &comp=comp
         &op=operation
         &op_list=op_list
         &del=yes
         }

   end. /* schedule_id = ""  THERE IS NO SCHEDULE  */

   /* CREATE FROZEN BILL OF MATERIALS FOR THIS ASSEMBLY*/
   find first icc_ctrl no-lock.

   find wo_mstr no-lock where recid(wo_mstr) = wo_recno.
   find wr_route no-lock where recid(wr_route) = wr_recno.

   /* CONSOLIDATE ABOVE 3 USES OF FOR EACH PK_DET */
   for each pk_det exclusive-lock
      where pk_user = mfguser
      break by pk_user
      by pk_part
      by pk_reference:

      /* BREAK BY IS USED TO CONSOLIDATE LIKE PART/REFERENCE  */
      /* NUMBER INTO ONE PK_DET RECORD.  PK_REFERENCE STORES  */
      /* THE OPERATION NUMBER                                 */

      if first-of(pk_reference) then temp_qty = 0.

      temp_qty = temp_qty + pk_qty.

      if not last-of(pk_reference) then delete pk_det.

      if last-of(pk_reference)
      then do:

         pk_qty = temp_qty.

         /* GET THE DEFAULT LOCATION IF NO SCHEDULE EXISTS */
         if schedule_id = ""
         then do:

            if op_wo_op <> integer(pk_reference)
            then do:

               find first ro_det no-lock where
                  ro_routing = (if routing > "" then routing else wr_part)
                  and ro_op = integer(pk_reference)
                  and (ro_start <= eff_date or ro_start = ?)
                  and (ro_end >= eff_date or ro_end = ?) no-error.
               if available ro_det
                  and can-find (loc_mstr where loc_loc = ro_wkctr
                  and loc_site = site) then pk_loc = ro_wkctr.

            end.
            else do:
               if can-find(loc_mstr where loc_site = wo_site and
                  loc_loc = op_wkctr) then pk_loc = op_wkctr.
            end.
         end. /* if schedule_id = "" */
         else if op_wo_op = integer(pk_reference) then do:
            if can-find(loc_mstr where loc_site = wo_site and
               loc_loc = op_wkctr) then pk_loc = op_wkctr.
         end. /* schedule_id <> "" */

         find first wod_det
            where wod_lot = wo_lot
              and wod_part = pk_part
              and (wod_op = integer(pk_reference))
            no-error.

         if not available wod_det
         then do:

            find in_mstr
               where in_part = pk_part
                 and in_site = wo_site
               no-lock no-error.

            if available in_mstr
            then do:

               if in_gl_set = "" then
                  find sct_det
                     where sct_part = in_part
                       and sct_sim = icc_gl_set
                       and sct_site = in_gl_cost_site
                  no-lock no-error.
               else
                  find sct_det
                     where sct_part = in_part
                       and sct_sim = in_gl_set
                       and sct_site = in_gl_cost_site
                  no-lock no-error.
            end.

            else do:
               find si_mstr
               where si_site = wo_site no-lock no-error.

               if available si_mstr
                  and si_gl_set = "" then
                     find sct_det
                        where sct_part = pk_part
                          and sct_sim = icc_gl_set
                          and sct_site = wo_site
                        no-lock no-error.
               else
                  find sct_det
                     where sct_part = pk_part
                       and sct_sim = si_gl_set
                       and sct_site = si_site
                  no-lock no-error.
            end.

            create wod_det.
            assign
               wod_lot = wo_lot
               wod_nbr = wo_nbr
               wod_part = pk_part
               wod_op = integer(pk_reference)
               wod_site = wo_site
               wod_bom_qty = pk_qty / bombatch
               wod_loc = ?
               wod_iss_date = ?.
            if recid(wod_det) = -1 then .
            if available sct_det then wod_bom_amt = sct_cst_tot.

            find qad_wkfl
               where qad_key1 = "MFWORLA"
                 and qad_key2 = wod_lot + wod_part + string(wod_op) no-error.

            if not available qad_wkfl
            then do:

               create qad_wkfl.
               assign
                  qad_key1 = "MFWORLA"
                  qad_key2 = wod_lot + wod_part + string(wod_op).
               if recid(qad_wkfl) = -1 then .
            end.

            assign
               qad_decfld[1] = pk_qty
               qad_decfld[2] = bombatch.

         end. /* not available wod_det */

         find first pkwkfl
            where pkrecid = recid(pk_det) no-lock
            no-error.

         if available pkwkfl
            and isspol = no
         then do:

            find in_mstr exclusive-lock
               where in_part = wod_part and in_site =
               wod_site no-error.

            if available in_mstr
            then do:

               if wod_qty_req >= 0 then
                  in_qty_req = in_qty_req -
                               max(wod_qty_req - wod_qty_iss,0).
               else
                  in_qty_req = in_qty_req -
                               min(wod_qty_req - wod_qty_iss,0).
            end.

            assign
               wod_qty_req = wod_qty_req + (pk_qty * op_qty_comp) / bombatch
               wod_qty_iss = wod_qty_req.
            delete pk_det.

            if available in_mstr
            then do:
               if wod_qty_req >= 0 then
                  in_qty_req = in_qty_req + max(wod_qty_req - wod_qty_iss,0).
               else
                  in_qty_req = in_qty_req + min(wod_qty_req - wod_qty_iss,0).
            end.
         end. /* if avail pkwkfl and isspol = no */
      end. /* if last-of pk_reference */
   end. /* for each pk_det exclusive-lock */

   /* TO RELEASE pk_det TABLE FROM MEMORY SO THAT THE CORRECT      */
   /* UPDATED RECORD IS RETRIEVED WHILE READ IN ORACLE ENVIRONMENT */
   release pk_det.

   forced_modissrc = no.

   if mod_issrc = no
      and (op_qty_comp + op_qty_rjct <> 0)
   then
      for each pk_det no-lock
         where pk_user = mfguser
           and pk_qty <> 0
         break by pk_user
         by pk_part
         by pk_loc :
/*GUI*/ if global-beam-me-up then undo, leave.


         if first-of(pk_part)
         then do:

            find pt_mstr no-lock
               where pt_part = pk_part no-error.

            if available pt_mstr
               and index("LS",pt_lot_ser) > 0
            then do:

               mod_issrc = yes.
               {pxmsg.i &MSGNUM=1119 &ERRORLEVEL=1}
               leave.
            end.
         end. /* first-of(pk_part) */

         if first-of(pk_loc) then trqty = 0.
         trqty = trqty + pk_qty.

         /* CHANGE QTY FROM ((pk_qty / bombatch) * (op_qty_comp + ..*/
         /*            TO   ((trqty  / bombatch) * (op_qty_comp + ..*/
         if last-of(pk_loc)
         then do:

            {gprun.i ""icedit2.p"" "(input ""ISS-WO"",
                                     input wo_site,
                                     input pk_loc,
                                     input pk_part,
                                     input """",
                                     input """",
                                     input ((trqty / bombatch)
                                             * (op_qty_comp + op_qty_rjct)),
                                     input if available pt_mstr
                                           then pt_um else """",
                                     input """",
                                     input """",
                                     output rejected)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            if rejected
            then do:

               mod_issrc = yes.
               forced_modissrc = yes.
               leave.
            end.
         end. /* if last-of(pk_loc) */
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


   if mod_issrc
   then do:

      if forced_modissrc then mod_issrc = no.
      {gprun.i ""reisrc01.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

      if forced_modissrc then mod_issrc = yes.
      /*V8+*/
   end.

   if is_wiplottrace_enabled()
      and is_operation_queue_lot_controlled
      (wo_lot, op_wo_op, OUTPUT_QUEUE)
   then do:
      view frame b.
      if is_operation_queue_lot_controlled
         (wo_lot, op_wo_op, INPUT_QUEUE)
      then do:
         run get_bkfl_input_wip_lots_from_user
            in h_wiplottrace_procs
            (input wo_lot, input op_wo_op,
            input entered_qty_comp + entered_qty_rjct,
            input conv_factor,
            input um, input site, input op_wkctr, input op_mch,
            output undo_stat).

         if undo_stat then
            undo, retry.
      end.

      assign
         move_to_wkctr = op_wkctr
         move_to_mch = op_mch .

      if not is_last_operation(wo_lot, op_wo_op)
      then do:
         run get_destination_wkctr_mch_from_user
            in h_wiplottrace_procs
            (input wo_lot,
            input next_milestone_operation(wo_lot, op_wo_op),
            output move_to_wkctr,
            output move_to_mch,
            output undo_stat).

         if undo_stat then undo, retry.
      end.

      if not is_last_operation(wo_lot, op_wo_op)
      then do:
         run get_bkfl_output_wip_lots_from_user
            in h_wiplottrace_procs
            (input wo_lot, input op_wo_op,
            input entered_qty_comp,
            input conv_factor,
            input um, input true,
            input site, input op_wkctr, input op_mch, output undo_stat).

         if undo_stat then
            undo, retry.
      end.

      if entered_qty_rjct <> 0
      then do:

         run get_std_labor_reject_wip_lots_from_user
            in h_wiplottrace_procs
            (input wo_lot, input op_wo_op,
            input entered_qty_rjct,
            input conv_factor,
            input um, input op_wo_op,
            input site, input op_wkctr, input op_mch,
            output undo_stat).

         if undo_stat then
            undo, retry.
      end.

      if is_last_operation(wo_lot, op_wo_op)
      then do:
         old_mod_issrc = mod_issrc.
         mod_issrc = true.
         run bkfl_create_receive_sr_wkfl in h_wiplottrace_procs
            (wo_lot, entered_qty_comp - entered_qty_rjct).
      end.
   end.

   find next wr_route no-lock
      where wr_lot = op_wo_lot
        and wr_op > op_wo_op no-error.

   if not available wr_route
   then do:

      find wo_mstr
         where wo_lot = op_wo_lot no-lock no-error.

      if available wo_mstr then

      rct-block:
      do on error undo rct-block, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


         find pt_mstr no-lock
            where pt_part = wo_part no-error.

         if ((available pt_mstr and index("LS",pt_lot_ser) > 0)
            and op_qty_comp <> 0)
            or mod_issrc = yes then do:
            wo_recid = recid(wo_mstr).

            {gprun.i ""reisrc02.p""
               "(output trans-ok,
                 output undo-input)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            if not trans-ok then
               undo loop1, retry.

            if undo-input then
               undo loop1, retry.
         end.
         else do:

            if op_qty_comp <> 0 then do:

               do for ptmstr:
                  find ptmstr where ptmstr.pt_part = wo_part no-lock
                     no-error.

                  /* CHANGED RUN FILE FROM icedit2.p TO icedit3.p */
                  {gprun.i ""icedit3.p""
                     "(input ""RCT-WO"",
                       input if wo_site > """" then wo_site
                             else if available ptmstr then ptmstr.pt_site
                             else """",
                       input if wo_loc > """" then wo_loc
                             else if available ptmstr then ptmstr.pt_loc
                             else """",
                       input wo_part,
                       input """",
                       input """",
                       input op_qty_comp,
                       input if available ptmstr then ptmstr.pt_um
                             else """",
                       input """",
                       input """",
                       output rejected)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                  if rejected = yes then
                     undo loop1, retry loop1.

               end.
            end. /* IF OP_QTY_COMP <> 0 */

            if not rejected
            then do:

               create sr_wkfl.
               assign
                  sr_userid = mfguser
                  sr_lineid = "+" + wo_part
                  sr_site = wo_site
                  sr_loc = wo_loc
                  sr_qty = op_qty_comp.

               if recid(sr_wkfl) = -1 then .
               if available pt_mstr then
                  if sr_loc  = "" then sr_loc = pt_loc.
            end.
         end. /*else do*/

         /*TEST FOR ATTRIBUTE CONFLICTS*/
         for each sr_wkfl
            where sr_userid = mfguser
              and sr_lineid = "+" + wo_part no-lock:
/*GUI*/ if global-beam-me-up then undo, leave.


            {gprun.i ""worcat01.p"" "(input recid(wo_mstr),
                                      input sr_site,
                                      input sr_loc,
                                      input sr_ref,
                                      input sr_lotser,
                                      input eff_date,
                                      input sr_qty,
                                      input-output chg_assay,
                                      input-output chg_grade,
                                      input-output chg_expire,
                                      input-output chg_status,
                                      input-output assay_actv,
                                      input-output grade_actv,
                                      input-output expire_actv,
                                      input-output status_actv,
                                      output trans-ok)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            if not trans-ok
            then do:

               if mod_issrc
               then do:

                  next-prompt site.
                  undo rct-block, retry.
               end.
               else do with frame b:
                  next-prompt mod_issrc with frame b.
                  undo loop1, retry.
               end.
            end.
         end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /*for each sr_wkfl*/

      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /*if avail wo_mstr*/
   end. /*if not avail wr_route (ie last op)*/

   view frame b.

   if is_wiplottrace_enabled()
      and is_operation_queue_lot_controlled
      (wo_lot, op_wo_op, OUTPUT_QUEUE)
   then do:
      if is_last_operation(wo_lot, op_wo_op)
      then do:
         /* IN THIS CASE WE DIDN'T GET OUTPUT WIP LOTS        */
         /* FROM THE USER; WE USE THE LOTSER'S ENTERED        */
         /* IN SR_WKFL FOR THE FINISHED MATERIAL INSTEAD.     */
         /* THE BACKFLUSH SUBROUTINE REBKFLA.P WILL BACKFLUSH */
         /* THIS LIST INTO WIP, THEN RECEIVE.P WILL MOVE      */
         /* IN TO FINISHED GOODS INVENTORY.                   */

         run init_bkfl_output_wip_lot_temptable
            in h_wiplottrace_procs.

         for each sr_wkfl no-lock
            where sr_userid = mfguser
              and sr_lineid = "+" + op_part
            break by sr_lotser by sr_ref:

            accumulate sr_qty (sub-total by sr_ref).

            if last-of(sr_ref) then
               run create_bkfl_output_wip_lot_temptable
                  in h_wiplottrace_procs
                  (input sr_lotser,
                  input sr_ref,
                  (accum sub-total by sr_ref sr_qty) / conv_factor).
         end.
      end.

      /* CHECK FOR COMBINED LOTS - INPUT WIP AND COMPONENTS */
      /* TO A PARTICULAR OUTPUT WIP LOT                     */

      run bkfl_check_for_combined_lots in h_wiplottrace_procs
         (input wo_lot,
         input op_wo_op,
         input conv_factor,
         output result_status).

      if result_status = FAILED_EDIT then do:
         view frame a.
         view frame b.

         if batchrun then undo loop1, leave loop1.
         else undo, retry.
      end.

      /* CHECK FOR COMBINED LOTS - INPUT WIP AND COMPONENTS */
      /* TO A PARTICULAR REJECT WIP LOT                     */

      run std_labor_chk_combnd_lots_in_rjct in h_wiplottrace_procs
         (input wo_lot,
         input op_wo_op,
         input conv_factor,
         output result_status).

      if result_status = FAILED_EDIT then do:
         view frame a.
         view frame b.

         if batchrun then undo loop1, leave loop1.
         else undo, retry.
      end.

      /* CHECK FOR SPLIT LOTS - OUTPUT WIP, REJECT WIP */
      /* TO A PARTICULAR INPUT WIP LOT                 */

      consider_output_qty = yes.

      run std_labor_check_for_split_lots in h_wiplottrace_procs
         (input wo_lot,
         input op_wo_op,
         input conv_factor,
         input consider_output_qty,
         output result_status).

      if result_status = FAILED_EDIT then do:
         view frame a.
         view frame b.

         if batchrun then undo loop1, leave loop1.
         else undo, retry.
      end.

      /* CHECK FOR MAX LOT SIZE EXCEEDED */

      run bkfl_max_lotsize_check in h_wiplottrace_procs
         (input wo_lot, input op_wo_op, input conv_factor).

      /* RESTORE MOD_ISSRC SO THAT REOPTR10.P WILL                    */
      /* BUILD THE RIGHT PK_DET QUANTITIES IF ORIGINALLY IT WAS FALSE */

      if is_last_operation(wo_lot, op_wo_op)
      then
         mod_issrc = old_mod_issrc.
   end.

   yn = yes.

   /*PLEASE CONFIRM UPDATE*/
   {pxmsg.i &MSGNUM=32 &ERRORLEVEL=1 &CONFIRM=yn &CONFIRM-TYPE='LOGICAL'}
   if yn = no then undo, retry.

   /* NOW THAT WE HAVE LAST INPUT FROM USER, RECHECK INVENTORY*/
   {gprun.i ""reoptr1f.p"" "(input """", output rejected)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   if rejected then undo, retry.

   /* LOCK THE INVENTORY MASTER RECORDS IN PART NUMBER ORDER.      */
   /* BY PREVENTING LOCKING IN A RANDOM ORDER, THE POSSIBLITY OF   */
   /* A DEADLY EMBRACE ON THIS FILE WILL BE PREVENTED.             */
   if schedule_id <> ? then do:
      {gprun.i ""reoptr1h.p"" "(input schedule_id,
                                input wo_part,
                                input op_wo_op,
                                input wo_site,
                                input op_list)"
         }
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
   undo-input-top = no.
end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /*loop1*/
